<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Config;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }
    public function banner(){
        $data = Db::name('banner')->order("ord asc")->select();
        foreach ($data as $k=>$v){
            $data[$k]['image'] = 'https://oss.bigchun.com'.$v['image'];
        }
        $this->success('请求成功',$data);
    }
    /**
     * 根据经纬度获取城市名称
     * @param $longitude
     * @param $latitude
     * @return mixed|string
     */
    public function cityName()
    {
        $longitude=$this->request->request('longitude',114.06933);
        $latitude=$this->request->request('latitude',22.55251);
        $key='3G5BZ-I2L36-DWMSV-EPA63-UIVB6-T7F2X';
        //调取腾讯接口,其中ak为key,注意location纬度在前，经度在后
        $api = "https://apis.map.qq.com/ws/geocoder/v1/?location=" . $latitude . "," . $longitude . "&output=json&pois=1&key=$key";
        $content = file_get_contents($api);
        // echo $content;
        $arr = json_decode($content, true);
        //echo $arr['result']['address_component']['province'];
        //print_r($arr);exit;
        if ($arr['status'] == 0) {
            $this->success('请求成功',$arr['result']['address_component']);
        } else {
           $this->error('失败');
        }
    }
    public function category(){
        $data = Db::name('recovery_category')->where(['pid'=>0,'deletetime'=>null])->select();
        $this->success('请求成功',$data);
    }
    public function categorytwo(){
        $id=$this->request->request('id');
        if(!$id){
            $this->error('缺少必传参数');
        }
        $data = Db::name('recovery_category')->where(['pid'=>$id,'deletetime'=>null])->select();
        $this->success('请求成功',$data);
    }
    public function recovery_weight(){
        $config = Config::get('site');
        $weight = explode(',', $config['recovery_weight']);
        $this->success('请求成功',$weight);
    }
}
